package com.booklove.service.order;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.booklove.domain.dto.PageDTO;
import com.booklove.domain.po.Notes;
import com.booklove.domain.po.Notesjudge;
import com.booklove.domain.query.NotesQuery;
import com.booklove.domain.vo.NotesVO;
import com.booklove.mapper.NotesMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 笔记 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-09-22
 */
@Service
public class NotesServiceImpl extends ServiceImpl<NotesMapper, Notes> implements NotesService {

    @Override
    public PageDTO<NotesVO> queryNotessPage(NotesQuery notesQuery) {
        // 1.添加排序规则
        // 使用内置的函数转换并且 设置规则
        List<OrderItem> orderItems = notesQuery.toMpOrderItems();

        // 获取分页对象和排序情况
        Page<Notes> page = notesQuery.toMpPageDefaultSortByIdAsc(orderItems.toArray(new OrderItem[0]));
        /*
        查询
         */
        Page<NotesVO> p = baseMapper.selectPageVO(page, notesQuery.getName(),notesQuery.getStatus());

        // 获取数据信息
        return PageDTO.of(p, NotesVO.class);
    }

    @Override
    public void saveJudgeNote(Notesjudge notesjudge) {
        baseMapper.saveJudgeNote(notesjudge);
    }

    @Override
    public void create(Notes notes) {

    }

}
